package com.picolov;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

public class StringConverterTest {

	@Test
	public void testConvertStringToObject() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", "pico");
		map.put("class", "3A");
		map.put("nullValue", null);
		map.put("emptyString", "");
		map.put("emptyMap", new HashMap<String, Object>());
		Map<String, Object> anotherMap = new HashMap<String, Object>();
		anotherMap.put("math", 90);
		Map<String, Object> bioMap = new HashMap<String, Object>();
		bioMap.put("week1", 60);
		bioMap.put("week2", 60);
		anotherMap.put("bio", bioMap);
		Map<String, Object> yetOtherMap = new HashMap<String, Object>();
		Map<String, Object> yetOtherOtherMap = new HashMap<String, Object>();
		yetOtherMap.put("day1", 65);
		yetOtherMap.put("day2", 55);
		yetOtherMap.put("week1", yetOtherOtherMap);
		yetOtherMap.put("week2", 70);
		anotherMap.put("chem", yetOtherMap);
		anotherMap.put("physic", 100);
		map.put("anotherMap", anotherMap);
		
		String mapContent = map.toString();
		Map<String, Object> result = (Map<String, Object>) StringConverter.convertStringToObject(mapContent.toString());
		System.out.println("before : " + mapContent);
		System.out.println("after  : " + result.toString());
		assertTrue(ContentChecker.isEquals(map, result, ContentChecker.MAP_LENGTH));
		assertTrue(ContentChecker.isEquals(map, result, ContentChecker.MAP_KEY));
		assertTrue(ContentChecker.isEquals(map, result, ContentChecker.MAP_CONTENT));
		
		List<Object> list = new ArrayList<Object>();
		list.add("apel");
		list.add("mangga");
		List<Object> otherList = new ArrayList<Object>();
		List<Object> otherOtherList = new ArrayList<Object>();
		otherOtherList.add("nanas1.1");
		otherOtherList.add("nanas1.2");
		otherOtherList.add("nanas1.3");
		otherOtherList.add("nanas1.4");
		otherList.add(otherOtherList);
		otherList.add("nanas2");
		otherList.add("nanas3");
		list.add(otherList);
		list.add("jeruk");
		List<Object> yetOtherList = new ArrayList<Object>();
		yetOtherList.add("pepaya1");
		yetOtherList.add("pepaya2");
		yetOtherList.add("pepaya3");
		yetOtherList.add("pepaya4");
		list.add(yetOtherList);
		System.out.println("before : " + list.toString());
		List<Object> resultList = (List<Object>) StringConverter.convertStringToObject(list.toString());
		System.out.println("after  : " + resultList);
		assertTrue(resultList.equals(list));
	}

}
